//
//  UIBarButtonItem+Extension.m
//  Project
//
//  Created by 冯东辉 on 2018/9/12.
//  Copyright © 2018年 FengDongHui. All rights reserved.
//

#import "UIBarButtonItem+Extension.h"
#import "UILabel+Extension.h"

@implementation UIBarButtonItem (Extension)

+(UIBarButtonItem *)barButtonItemWithImageName:(NSString *)imageName
                                  higImageName:(NSString *)higIamgeName
                                        action:(SEL)action
                                        target:(id)target {
    
    UIButton *btn1 = [[UIButton alloc]init];
    [btn1 setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    [btn1 setImage:[UIImage imageNamed:higIamgeName] forState:UIControlStateHighlighted];
    btn1.frame = CGRectMake(0, 20, 60, 44);
    btn1.imageEdgeInsets = UIEdgeInsetsMake(0, -24, 0, 24);
    [btn1 addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    
    return [[UIBarButtonItem alloc]initWithCustomView:btn1];
}


+(UIBarButtonItem *)barButtonItemWithImageName:(NSString *)imageName
                             SelectedImageName:(NSString *)SelectedImage
                                        action:(SEL)action
                                        target:(id)target {
    
    UIButton *btn1 = [[UIButton alloc]init];
    [btn1 setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    [btn1 setImage:[UIImage imageNamed:SelectedImage] forState:UIControlStateSelected];
    btn1.size = btn1.currentImage.size;
    
    [btn1 addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    
    return [[UIBarButtonItem alloc]initWithCustomView:btn1];
}


+(UIBarButtonItem *)barButtonItemWithTitleName:(NSString *)imageName
                                         color:(UIColor *)color
                                        action:(SEL)action
                                        target:(id)target {
    
    UIButton *btn1 = [[UIButton alloc]init];
    [btn1 setTitle:imageName forState:UIControlStateNormal];
    btn1.titleLabel.font = [UIFont systemFontOfSize:17];
    [btn1 setTitleColor:color forState:UIControlStateNormal];
    btn1.size = CGSizeMake([btn1.titleLabel getLabelSize:creatSize(100, 30)].width+10, 30);
    
    [btn1 addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    
    return [[UIBarButtonItem alloc]initWithCustomView:btn1];
}


@end
